package com.example.demo.model;

import com.example.demo.enums.ResultCodeEnum;
import lombok.Data;

@Data
public class Result <T>{

    public int code;
    private String errMsg;
    private T data;
    public static <T> Result success(T data){
        Result result = new Result();
        result.setData(data);
        result.setCode(ResultCodeEnum.SUCCESS.getCode());
        return result;

    }
    public static <T> Result fail(int code, String errMsg){
        Result result = new Result();
        result.setErrMsg(errMsg);
        result.setCode(ResultCodeEnum.FAIL.getCode());
        return result;

    }

    public static <T> Result fail( String errMsg){
        Result result = new Result();
        result.setErrMsg(errMsg);
        return result;

    }
    public static <T> Result noLogin(){
        Result result = new Result();
        result.setErrMsg("未登录!");
        result.setCode(ResultCodeEnum.NO_LOGIN.getCode());
        return result;

    }

}
